//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"

//SAGITTARIUS headers:
#include "sagittarius/mem/sysalloc.h"

//system headers:
#include <windows.h>

void* sg_sysalloc(size_t n_pgs) {
    //this function is the Page Master
    void* r = VirtualAllocEx(
        GetCurrentProcess(), //process handle
        NULL, //preferred address
        n_pgs*SG_PAGE_SIZE, //size
        MEM_COMMIT, //Allocation type. Just specifies that we really do want the memory
        PAGE_READWRITE //Protection: see http://msdn.microsoft.com/en-us/library/aa366786%28v=vs.85%29.aspx
        );
    AN(r, "sg_sysalloc failure");
    return r;
}

int sg_sysfree(void* p, size_t n_pgs) {
    //MS is opposite of "return zero for success" protocol
    return !VirtualFreeEx(
        GetCurrentProcess(),
        p,
        0,
        MEM_RELEASE);
}